﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Collections.Generic;

using YouHP.Model;
using YouHP.BLL;

namespace web.admin
{
    public partial class Prescription : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            string condStr = string.Format("[Prescription].[IsClassic]=0");
            List<PrescriptionInfo> nonClassicPrescriptionList = PrescriptionBLL.Instance.GetPrescriptionList(condStr);

            for (int idx = 0; idx < nonClassicPrescriptionList.Count; idx++)
            {
                DoctorInfo doctorInfo = DoctorBLL.Instance.GetDoctorInfo(nonClassicPrescriptionList[idx].DoctorId);
                nonClassicPrescriptionList[idx].DoctorName = doctorInfo.Name;
                nonClassicPrescriptionList[idx].DoctorHospital = doctorInfo.Hospital;
            }

            this.nonClassicPrescriptionList.DataSource = nonClassicPrescriptionList;
            this.nonClassicPrescriptionList.DataBind();
        }

        protected void BtnSetSelectedAsClassic_Click(object sender, EventArgs e)
        {
            try
            {
                int[] idList = new int[this.nonClassicPrescriptionList.Rows.Count];

                for (int rowIndex = 0; rowIndex < this.nonClassicPrescriptionList.Rows.Count; rowIndex++)
                {
                    bool ischeck = ((CheckBox)this.nonClassicPrescriptionList.Rows[rowIndex].Cells[0].FindControl("chk")).Checked;
                    if (ischeck)
                    {
                        idList[rowIndex] = Convert.ToInt32(this.nonClassicPrescriptionList.DataKeys[rowIndex].Value);
                    }
                }

                PrescriptionBLL.Instance.UpdatePrescriptionsClassicState(idList, true);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            Bind();
        }
    }
}
